package com.binhai.springboot.user.controller;

import com.binhai.springboot.person.bean.PersonBean;
import com.binhai.springboot.user.bean.UserBean;
import com.binhai.springboot.user.service.UserService;
import org.apache.poi.hssf.usermodel.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService service;

    @RequestMapping("/toMain.do")
    public String toMain(){

        return "user/main";
    }

    @RequestMapping("/getAllData.do")
    @ResponseBody
    public List getAllData(){

        return service.getAllData();
    }


    @RequestMapping("/selectData.do")
    @ResponseBody
    public List selectData(@RequestBody UserBean bean){

        return service.selectData(bean.getName ());
    }
    @RequestMapping("/forget.do")
    @ResponseBody
    public List forget(@RequestBody UserBean bean){

        return service.forget(bean.getBeizhu ());
    }

    @RequestMapping("/saveData.do")
    @ResponseBody
    public Map saveUser(@RequestBody UserBean bean){

        return service.saveData(bean);
    }
    @RequestMapping("/register.do")
    @ResponseBody
    public String register(UserBean bean){

        return service.register(bean);
    }
    @RequestMapping("/updateData.do")
    @ResponseBody
    public Map updateUser(@RequestBody UserBean bean){

        return service.updateData(bean);
    }
    @RequestMapping("/repass.do")
    public String repass(UserBean bean){

        return service.repass(bean);
    }
    @RequestMapping("/deleteData.do")
    @ResponseBody
    public Map deleteUser(@RequestBody UserBean bean){

        return service.deleteData(bean);
    }

    @RequestMapping("/deleteDatas.do")
    @ResponseBody
    public Map deleteDatas(/* @ResponseBody*/int[] ids){
//在上传文件的时候，spring框架会自动装配文件类型, 使用@RequestBody接收对象，所对应的content-type :application/json。所以当使用@RequestBody和文件上传的时候，会报错。
//
//解决办法：去掉@RequestBody注解
        return service.deleteDatas(ids);
    }

    /**
     * 加载看角色树
     * @return
     */
    @RequestMapping("/getAllTreeData.do")
    @ResponseBody
    public List getAllTreeData(){
        return service.getAllTreeData();
    }


    @RequestMapping("/login.do")
    public String login(UserBean bean, String code, PersonBean beanbean){
        return service.login(bean,code,beanbean);
    }
}
